feat(retrieval): Reciprocal Rank Fusion for hybrid BM25+vector scoring#31
Merged
feat(retrieval): Reciprocal Rank Fusion for hybrid BM25+vector scoring#31
Conversation
BM25-only blocks previously entered the composite scorer with similarity=0.0, making them unable to compete with vector-found blocks. RRF (k=60, Cormack et al. 2009) fuses both ranked lists so blocks found by both rankers score higher, and BM25-only blocks receive proportional relevance scores. Falls back to raw cosine similarity when BM25 is absent — zero behavioral change for users without rank_bm25 installed. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hybrid_retrieve(). When both vector search and BM25 produce results, Reciprocal Rank Fusion (k=60) merges the two ranked lists into a single relevance score per block. Blocks found by both rankers score higher; BM25-only blocks receive proportional scores instead ofsimilarity=0.0.rank_bm25is not installed or BM25 returns zero scores, the pipeline falls back to raw cosine similarity — identical to current behavior.compute_score()andScoringWeightsare untouched. RRF produces thesimilarityinput; everything downstream is unchanged.Before vs After
similarity=0.0(penalized)Test plan
uv run pytest tests/ -x -q)uv run ruff check src/ tests/— all checks passeduv run mypy --ignore-missing-imports src/elfmem/— no issues🤖 Generated with Claude Code